<?php

namespace app\model\plan\snap;

use app\model\TimeModel;

class Snap extends TimeModel
{
    const TYPE_POST = 1 ;
    const TYPE_EXAM = 2 ;
    const TYPE_DISCLOSE = 3 ;


    public static function typeData()
    {
        return [
            self::TYPE_POST  => '课程' ,
            self::TYPE_EXAM  => '考试' ,
            self::TYPE_DISCLOSE  => '交底' ,
        ] ;
    }

    protected $table = 'sj_snap';
    public static function logAdd($userId , $postId , $type , $imgUrl , $ret , $shiftId = 0){
        return self::create([
            'staff_id' => $userId,
            'courseware_id' => $postId ,
            'type' => $type ,
            'img_url' => $imgUrl ,
            'ret' => $ret ,
            'plan_id' => $shiftId
        ]) ;
    }
    public static function failTotal($userId ,$shiftId , $type , $time  )
    {
        $where[] = ['staff_id' , '=' , $userId] ;
        $where[] = ['plan_id', '=' , $shiftId] ;
        $where[] = ['type' , '=', $type] ;
        $where[] = ['ret', '=' , 0] ;
        $where[] = ['create_time', '>' , $time] ;

        return self::where($where)->count() ;
    }
    public static function snapImage($shiftId , $userId , $type)
    {
        return self::where('status' , 1)
            ->where('staff_id' , $userId)
            ->where('plan_id' , $shiftId)
            ->where('type' , $type)
            ->where('ret' , 1)
            ->field('id,img_url,create_time')
            ->select() ;
    }
    public static function snapSelImage($shiftId , $userId , $type)
    {
        return self::where('status' , 1)
            ->where('staff_id' , $userId)
            ->where('plan_id' , $shiftId)
            ->where('type' , $type)
            ->where('ret' , 1)
            ->where('sel_status' , 1)
            ->field('id,img_url,create_time')
            ->select() ;
    }

}